package cn.trda.service.impl;

import java.util.List;

import cn.trda.mapper.AsContactsMapper;
import cn.trda.pojo.Contacts;
import cn.trda.pojo.Customs;
import cn.trda.service.ContactService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ContactServiceImpl implements ContactService {
	@Autowired
	AsContactsMapper asContactsMapper;
	
	@Override
	public List<Contacts> getContactListByCustomerId(Long id) throws Exception {
		// TODO Auto-generated method stub
		return asContactsMapper.getContactListByCustomerId(id);
	}

	@Override
	public void addContacts(Customs customer) {
		asContactsMapper.deleteByCustomerId(customer.getId());
		List<Contacts> contacts=customer.getContactList();
		for (Contacts contact : contacts) {
			if(contact.getContactname()!=null&&contact.getContactemail()!=null&&contact.getContactfax()!=null&&contact.getContactrole()!=null&&contact.getContacttel()!=null){				
				contact.setCustomid(customer.getId());
				asContactsMapper.insert(contact);
			}
		}
	}

	

	
	
}
